/*
 * @lc app=leetcode.cn id=1941 lang=typescript
 *
 * [1941] 检查是否所有字符出现次数相同
 */

// @lc code=start
function areOccurrencesEqual(s: string): boolean {
    let cache = new Map<string, number>();
    for (let i = 0; i < s.length; i++) {
        const element = s[i];
        cache.set(element, (cache.get(element) || 0) + 1);
    }
    let temp: number = 0;
    for (const val of cache.values()) {
        if (temp === 0) {
            temp = val;
        } else {
            if (temp !== val) {
                return false;
            }
        }
    }
    return true;
}
// @lc code=end
